package com.ibeeking.found.content.api.feign.fallback;

import com.ibeeking.found.content.api.feign.ContentCouponBClient;
import com.ibeeking.found.content.api.common.dto.CouponInfoDTO;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class ContentCouponBFallbackFactory implements FallbackFactory<ContentCouponBClient> {
    @Override
    public ContentCouponBClient create(Throwable throwable) {
        return new ContentCouponBClient() {

            @Override
            public ResponseResult<List<CouponInfoDTO>>  queryInfoByIds(@RequestBody List<Long> ids) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "查询券失败。" + throwable.getMessage(), Collections3.emptyList());
            }
        };
    }
}
